package com.campus.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.campus.common.annotation.Log;
import com.campus.common.core.controller.BaseController;
import com.campus.common.core.domain.AjaxResult;
import com.campus.common.enums.BusinessType;
import com.campus.manage.domain.ClubAnnounce;
import com.campus.manage.service.IClubAnnounceService;
import com.campus.common.utils.poi.ExcelUtil;
import com.campus.common.core.page.TableDataInfo;

/**
 * 公告Controller
 * 
 * @author hehe
 * @date 2025-10-22
 */
@RestController
@RequestMapping("/manage/announce")
public class ClubAnnounceController extends BaseController
{
    @Autowired
    private IClubAnnounceService clubAnnounceService;

    /**
     * 查询公告列表
     */
    @PreAuthorize("@ss.hasPermi('manage:announce:list')")
    @GetMapping("/list")
    public TableDataInfo list(ClubAnnounce clubAnnounce)
    {
        startPage();
        List<ClubAnnounce> list = clubAnnounceService.selectClubAnnounceList(clubAnnounce);
        return getDataTable(list);
    }

    /**
     * 导出公告列表
     */
    @PreAuthorize("@ss.hasPermi('manage:announce:export')")
    @Log(title = "公告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ClubAnnounce clubAnnounce)
    {
        List<ClubAnnounce> list = clubAnnounceService.selectClubAnnounceList(clubAnnounce);
        ExcelUtil<ClubAnnounce> util = new ExcelUtil<ClubAnnounce>(ClubAnnounce.class);
        util.exportExcel(response, list, "公告数据");
    }

    /**
     * 获取公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('manage:announce:query')")
    @GetMapping(value = "/{announceId}")
    public AjaxResult getInfo(@PathVariable("announceId") Long announceId)
    {
        return success(clubAnnounceService.selectClubAnnounceByAnnounceId(announceId));
    }

    /**
     * 新增公告
     */
    @PreAuthorize("@ss.hasPermi('manage:announce:add')")
    @Log(title = "公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ClubAnnounce clubAnnounce)
    {
        return toAjax(clubAnnounceService.insertClubAnnounce(clubAnnounce));
    }

    /**
     * 修改公告
     */
    @PreAuthorize("@ss.hasPermi('manage:announce:edit')")
    @Log(title = "公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ClubAnnounce clubAnnounce)
    {
        return toAjax(clubAnnounceService.updateClubAnnounce(clubAnnounce));
    }

    /**
     * 删除公告
     */
    @PreAuthorize("@ss.hasPermi('manage:announce:remove')")
    @Log(title = "公告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{announceIds}")
    public AjaxResult remove(@PathVariable Long[] announceIds)
    {
        return toAjax(clubAnnounceService.deleteClubAnnounceByAnnounceIds(announceIds));
    }
}
